import { baseUrl } from './config'
let fetch = (api, data = {}) => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: `${baseUrl + api}`,
      data,
      success: res => {
        if (res.statusCode === 200) {
          resolve(res)
        } else {
          wx.hideLoading()
          wx.showModal({
            title: '对不起',
            content: `code:${res.statusCode}，请检查服务器代码`,
            showCancel: false
          })
          reject(res)
        }
      },
      fail: err => {
        console.log(err)
        reject(err)
      }
    })
  })
}
let query = param => {
  return fetch(
    'WebApi.ashx?Act=Query',
    { "param": JSON.stringify(param) }
  )
}
export {
  fetch,
  query
}